package Views;

import dao.ClienteDAO;
import entity.Cliente;
import java.sql.SQLException;
import java.util.List;
import javax.swing.table.AbstractTableModel;


public class TableModel extends AbstractTableModel {
    private static final long serialVersionUID = 1;
    private final int COL_NOME = 0;
    private final int COL_SOBRENOME = 0;
    private final int COL_RG = 0;
    private final int COL_CPF = 0;    
    private final int COL_ID = 0; 
    private final int COL_END = 0; 
    private final int COL_SALARIO = 0; 
    private List<Cliente> clientes;
    
    public TableModel(List<Cliente> lista) throws SQLException{        
        //ClienteDAO list = new ClienteDAO();                
        this.clientes = lista;
    }    
    
    public int getRowCount() {
        return this.clientes.size(); 
    }

    @Override
    public int getColumnCount() {
        return 7; //To change body of generated methods, choose Tools | Templates.
    }
    public String getColumnName(final int column) {    
      switch (column) {  
          case 0 :  
              return "Nome";  
          case 1 :  
              return "Sobrenome";
          case 2 :  
              return "RG";
          case 3 :  
              return "CPF";
          case 4 :  
              return "Endereço";
          case 5 :  
              return "Salario";
          case 6 :  
              return "ID";
          default :  
              return "?"; // nunca vai cair aqui, pois só tem 2 colunas  
      }    
   }  
    public Class getColumnClass(int columnIndex){
        switch (columnIndex) {  
          case 0 :  
              return String.class;  
          case 1 :  
             return String.class;  
          case 2 :  
              return String.class;  
          case 3 :  
              return String.class;  
          case 4 :  
              return String.class;  
          case 5 :  
             return double.class;  
          case 6 :  
              return int.class;  
          default :  
              return String.class;
        }
    }

    @Override
    public Object getValueAt(final int rowIndex,final int columnIndex) {
        Cliente c = clientes.get(rowIndex);
        switch (columnIndex) {  
          case 0 :  
              return c.getNome();  
          case 1 :  
              return c.getSobrenome();
          case 2 :  
              return c.getRg();
          case 3 :  
              return c.getCpf();
          case 4 :  
              return c.getEndereco();
          case 5 :  
              return c.getSalario();
          case 6 :  
              return c.getIdCliente();
          default :  
              return "?"; // nunca vai cair aqui, pois só tem 2 colunas  
      }    
    }
      /*public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        Cliente c = clientes.get(rowIndex);
        if(columnIndex == COL_NOME)
            c.setNome(aValue.toString());
        else if(columnIndex == COL_SOBRENOME)
            c.setSobrenome(aValue.toString());
        else if(columnIndex == COL_RG)
            c.setRg(aValue.toString());
        else if(columnIndex == COL_CPF)
             c.setCpf(aValue.toString());
        else if(columnIndex == COL_END)
             c.setEndereco(aValue.toString());
        else if(columnIndex == COL_SALARIO)
             c.setSalario(Double.parseDouble(aValue.toString()));
        else if(columnIndex == COL_ID)
             c.setIdCliente(Integer.parseInt(aValue.toString()));
        fireTableDataChanged();
    }*/
    
    
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        //no nosso caso todas vão ser editáveis, entao retorna true pra todas
        return false;
    }
    
}
